package com.lm.itextpdf.example;

import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Image;
import com.itextpdf.io.image.ImageData;
import com.itextpdf.io.image.ImageDataFactory;

public class AddImageToPDFExample {
    public static void main(String[] args) throws Exception {
        String dest = "image_example.pdf";
        String imagePath = "example.jpg";

        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        Document document = new Document(pdfDoc);

        ImageData data = ImageDataFactory.create(imagePath);
        Image img = new Image(data);

        document.add(img);
        document.close();

        System.out.println("PDF with image created at: " + dest);
    }
}
